/**
 * Creates new IconsStateProvider Class for saving state of icons
 * @constructor
 * @param {Object} config Configuration object
 */
Ext.ns('Ext.ux.Desktop');
Ext.ux.Desktop.IconsStateProvider = function(config){
	
	this.setProvider = function(provider){
		
	   	Ext.state.Manager.setProvider(provider);
	   	
	   	this.provider = Ext.state.Manager.getProvider();
	}
	
	this.getIcon = function(icon){
		if(typeof icon == 'object')
			return this.getAllIcons()[icon.id];
		else if(typeof icon == 'string' || typeof icon == 'number')
			return this.getAllIcons()[icon];
	}
	
	this.getAllIcons = function(){
		var array = this.provider.get('desktop_iconArray') || {};
		
		return array;
	}
	
	this.setIcon = function(icon){
		
		var icons = this.getAllIcons();
		
		icons[icon.id] = icon;
		
		this.provider.set('desktop_iconArray', icons);
	}
	
	this.setAllIcons = function(obj){
		
		this.provider.set('desktop_iconArray', obj);
	}
	
	//deleting icons
	this.getAllDeletedIcons = function(){
		var obj = this.provider.get('desktop_iconArray') || {};
		
		var retObj = new Object();
		for( var i in obj ){
			if(!obj[i].enable)
				retObj[i] = obj[i];
		}
		
		return retObj;
	}	
	
	this.deleteIcon = function(icon){
		//var icons = this.getAllIcons();
		console.log('icon');
		console.log(icon);
		icon.enable = false;
		
		this.setIcon(icon);
	}
	
	this.setIconActive = function(iconID){
		
		var icon = this.getIcon(iconID);		
		icon.enable = true;		
		this.setIcon(icon);
	}
	
	//constructor
	this.setProvider(config.provider);
	Ext.EventManager.on(window, 'unload', function(){

	});
}